<?php
class MapperTags
{
		public function __construct() {
		mysql_connect(HOST, LOGIN, PASS) or die('No connect with database');
		mysql_query('SET NAMES utf8');
		mysql_select_db(DB) or die("error");
	}
	function __destruct() {
		//mysql_close();
	}

	public function getTagsOnArticle($id) {
		$query = "SELECT tags.id_tag, tags.title, tags.count FROM tags JOIN articles_tags ON articles_tags.id_tag = tags.id_tag WHERE articles_tags.id_article = {$id}";
		$r = mysql_query($query) or die(mysql_error());
		$n = mysql_num_rows($r);
		$tags = array();
		for ($i = 0; $i < $n; $i++) {
			$row = mysql_fetch_assoc($r);
			$tag = new ModelTags($row);
			$tags[] = $tag;
		}
		return $tags;
	}
	public function getAllTags() {
		$query = "SELECT * FROM tags";
		$r = mysql_query($query) or die(mysql_error());
		$n = mysql_num_rows($r);
		$tags = array();
		for ($i = 0; $i < $n; $i++) {
			$row = mysql_fetch_assoc($r);
			$tag = new ModelTags($row);
			$tags[] = $tag;
		}
		return $tags;
	}
	public function delComment($id) {
		$id   = Validator::validatorIdSql($id);
		$query = "DELETE FROM `comments` WHERE `id_comments` = {$id}";
		$r = mysql_query($query) or die(mysql_error());
		if ($r) {
			return true;
		} else {
			return false;
		}
	}
}
